package Server.junit;

import Server.map.Box;
import Server.players.Carnivorous;
import Server.players.Dino;
import Server.players.Herbivorous;
import junit.framework.TestCase;

public class HerbTest extends TestCase {

	private Herbivorous h;
	protected void setUp() throws Exception {
		super.setUp();
		h = new Herbivorous(1);
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}


	public void testIsCarniv() {
		assertFalse(h.isCarniv());
	}

	public void testIsHerb() {
		assertTrue(h.isHerb());
	}

	public void testMaxDistance() {
		assertTrue(h.maxDistance() == 2);
	}

	public void testEat() {
		Box b = new Box(1,1,false);
		b.putVegetable();
		int e = b.getFoodEnergy();
		int en = h.getEnergy();
		h.eat(b);
		assertTrue(h.getEnergy() == en+e);
	}

	public void testFight() {
		Carnivorous c = new Carnivorous(2);
		h.grow();
		assertEquals(h.fight(c), c);
	}

	public void testHerbivorousInt() {
		h = new Herbivorous(3);
		assertNotNull(h);
	}

	public void testHerbivorousIntBox() {
		h = new Herbivorous(3, new Box(1,1,false));
		assertNotNull(h);
	}

	public void testHerbivorousHerbivorous() {
		Herbivorous h1 = new Herbivorous(h);
		assertNotNull(h1);
	}

	public void testOlder() {
		int age = h.getAge();
		h.older();
		assertFalse(age == h.getAge());
	}

	public void testEgg() {
		int energy = h.getEnergy();
		if (h.egg()){
			assertTrue(h.getEnergy() == energy - Dino.ENERGY_REQUIRED_EGG);
		} else {
			assertTrue(h.getEnergy() < 0);
		}
	}

	public void testGrow() {
		int energy = h.getEnergy();
		int dimension = h.getDimension();
		if (h.grow()){
			assertTrue(h.getEnergy() == energy - (dimension*1000)/2);
			assertTrue(h.getDimension() == dimension + 1);
		} else {
			assertTrue(h.getEnergy() < 0);
		}
	}

	public void testMove() {
		Box dest = new Box(3,3,false);
		Herbivorous h = new Herbivorous(3, new Box(1,1, false));
		int energy = h.getEnergy();
		if (h.move(dest, 2)){
			assertTrue(h.getEnergy() == energy - 10 * Math.pow(2, 2));
			assertEquals(new Box(h.getX(), h.getY(), false), dest);
		} else {
			assertTrue(h.getEnergy() < 0);
		}
	}

}
